﻿package bipede.animation
{
	import events.MoveEvent;
	import flash.events.TimerEvent;
	import fab.geom.Bezier;
	import fab.geom.Drawer;
	import flash.geom.Point;
	
	public class Gestes extends AnimationTimer
	{
		private var cb_curve_droite:Bezier;
		private var cb_curve_gauche:Bezier;
		
		public function Gestes( _type:String )
		{
			type = _type;
			super();
		}
		override public function start():void
		{
			var arr_gauche:Vector.<Point> = new Vector.<Point>;
			var arr_droite:Vector.<Point> = new Vector.<Point>;
			switch( type )
			{
				case "leve_les_bras" :
				
					arr_gauche.push( cfg.main_gauche.doigt );
					arr_gauche.push( cfg.cible.add( new Point( 100,40 ) ) );
					arr_gauche.push( cfg.cible.add( new Point( 50,0 ) ) );
					cb_curve_gauche = new Bezier( arr_gauche );
					
					arr_droite.push( cfg.main_droite.doigt );
					arr_droite.push( cfg.cible.add( new Point( -100,-40 ) ) );
					arr_droite.push( cfg.cible.add( new Point( -50,0 ) ) );			
					cb_curve_droite = new Bezier( arr_droite );
					
					//Drawer.drawCurve( Main.drawings.graphics, arr_droite, 0xFF0000 );
					//Drawer.drawCurve( Main.drawings.graphics, arr_gauche, 0x0000FF );
			
				break;	
				
				case "baisse_les_bras" :
				
					arr_gauche.push( cfg.main_gauche.doigt );
					arr_gauche.push( cfg.cible.add( new Point( 50,0 ) ) );
					arr_gauche.push( cfg.cible.add( new Point( 100,40 ) ) );
					cb_curve_gauche = new Bezier( arr_gauche );
					
					arr_droite.push( cfg.main_droite.doigt );
					arr_droite.push( cfg.cible.add( new Point( -50,0 ) ) );			
					arr_droite.push( cfg.cible.add( new Point( -100,-40 ) ) );
					cb_curve_droite = new Bezier( arr_droite );
					
					//Drawer.drawCurve( Main.drawings.graphics, arr_droite, 0xFF0000 );
					//Drawer.drawCurve( Main.drawings.graphics, arr_gauche, 0x0000FF );
			
				break;		
				
				case "balance_les_bras" :
				
					arr_gauche.push( cfg.main_gauche.doigt );
					arr_gauche.push( cfg.cible.add( new Point( 50,0 ) ) );
					arr_gauche.push( cfg.cible.add( new Point( 100,40 ) ) );
					cb_curve_gauche = new Bezier( arr_gauche );
					
					arr_droite.push( cfg.main_droite.doigt );
					arr_droite.push( cfg.cible.add( new Point( -50,0 ) ) );			
					arr_droite.push( cfg.cible.add( new Point( -100,-40 ) ) );
					cb_curve_droite = new Bezier( arr_droite );
					
					//Drawer.drawCurve( Main.drawings.graphics, arr_droite, 0xFF0000 );
					//Drawer.drawCurve( Main.drawings.graphics, arr_gauche, 0x0000FF );
			
				break;					
			}			
			super.start();
		}	
		override public function _tick( event:TimerEvent ):void
		{
			avancement += cfg.vitesse;
			
			if ( avancement >= 1 )
			{
				dispatchEvent( new MoveEvent( MoveEvent.ENDMOVING ) );
				stop();
			}
			dispatchEvent( new MoveEvent( MoveEvent.MOVEMAINDROITE, cb_curve_droite.pointAt( avancement ), null ) );
			dispatchEvent( new MoveEvent( MoveEvent.MOVEMAINGAUCHE, cb_curve_gauche.pointAt( avancement ), null ) );
		}
	}
}